package com.sword.service.impl.stock.product;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sword.constant.MessageConstant;
import com.sword.mapper.stock.product.ProductClassMapper;
import com.sword.page.PageResult;
import com.sword.page.QueryPageBean;
import com.sword.pojo.stock.product.Productclass;
import com.sword.pojo.system.Employee;
import com.sword.service.impl.BaseServiceImpl;
import com.sword.service.impl.BasicBaseServiceImpl;
import com.sword.service.stock.product.ProductClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ProductClassServiceImpl extends BasicBaseServiceImpl<Productclass> implements ProductClassService {
	
	@Autowired
	private ProductClassMapper productClassMapper;
	
	/**
	 * 分页查询商品总分类管理
	 *
	 * @param queryPageBean 分页查询数据
	 * @return com.sword.page.PageResult
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 10:47
	 */
	@Override
	public PageResult queryProductClass(QueryPageBean queryPageBean) {
		
		QueryWrapper<Productclass> wrapper =new QueryWrapper<>();
		
		String queryString = queryPageBean.getQueryString();
		
		// 如果queryString有值
		if (queryString != null) {
			wrapper.like("productclassid", queryString).or().like("Remark", queryString);
		}
		
		IPage<Productclass> ipage = super.queryPageList(wrapper, queryPageBean.getPage(), queryPageBean.getLimit());
		
		return new PageResult(0, MessageConstant.QUERY_PRODOCTCLASS_SUCCESS, ipage.getTotal(), ipage.getRecords());
	}
	
	/**
	 * 添加商品总分类数据
	 *
	 * @param productclass 商品总分类数据
	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 11:24
	 */
	@Override
	public Integer addProductClass(Productclass productclass) {
		productclass.setCreateDate(new Date());
		return super.save(productclass);
	}
	
	/**
	 * 编辑商品总分类
	 *
	 * @param productclass 商品总分类数据
 	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 11:24
	 */
	@Override
	public Integer editProductClass(Productclass productclass) {
		return super.update(productclass);
	}
	
	/**
	 * 删除商品总分类
	 *
	 * @param id 删除商品总分类的id
	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 11:36
	 */
	@Override
	public Integer deleteProductClass(Integer id) {
		return super.deleteById(Long.valueOf(id));
	}
	
	 /**
	 * 查询所有商品总分类编号
	 *
	 * @return java.util.List<java.lang.String>
	 * @author <1254087415@qq.com>
	 * @since 2021/6/7 13:32
	 */
	@Override
	public List<Map<String, Object>> getAllProductClassId() {
		QueryWrapper<Productclass> queryWrapper=new QueryWrapper();
		queryWrapper.select("productclassid", "PC_Name as name");
		List<Map<String, Object>> allProductClassId = productClassMapper.selectMaps(queryWrapper);
		System.out.println(allProductClassId);
		return allProductClassId;
	}
	
}
